home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / door / twview93.zip / TEXTDISP.INC < prev    next >
Text File  |  1992-06-07  |  6KB  |  187 lines

  1. function DisplayPort( WhichPort : Portindex ) : string;
  2. begin
  3.   if WhichPort = 0 then
  4.     DisplayPort := ' Port data not found!'
  5.   else
  6.     with space.ports.data[ WhichPort ] do
  7.       DisplayPort :=  ' F:' + str(amts[fuel], 5) + ' ' + str(usage[fuel],3) +
  8.                       '% O:' + str( amts[ organics], 5) + ' ' + str(usage[organics],3) +
  9.                       '% E:' + str( amts[ equipment ], 5 )+ ' ' + str(usage[equipment],3) + '%';
  10. end; {DisplayPort}
  11.  
  12. function DisplayNote( s : sector ) : string;
  13. { print the note associated with sector s }
  14. var
  15.   n : 0..MaxNote;
  16. begin
  17.   n := NoteNumber( s );
  18.   if n = 0 then
  19.     Displaynote := ' Missing note! '
  20.   else
  21.     Displaynote := ' ' + space.notes.data[n].info;
  22. end; {write note}
  23.  
  24. procedure DisplaySector( s : sector; whatIs : string; dist : integer;  
  25.                          ToFile : boolean; var TheFile : text);
  26. var
  27.   line : string;
  28. begin
  29.   with space.sectors[s] do
  30.     begin
  31.       line := 'Sctr:' + str( s, 3);
  32.       if dist <> Error then
  33.         line := line + WhatIs + str( dist, 2 );
  34.       if number = UnExplored then
  35.         if verbose then
  36.           line := line + ' Unexplored sector'
  37.         else
  38.           line := line + ' UEX';
  39.       if portType <> NotAPort then
  40.         begin
  41.           line := line + ' port ' + status( portType );
  42.           if portType <> Class0 then
  43.             line := line + DisplayPort( portnumber( s ) );
  44.         end; {if port}
  45.       if (etc and SpaceLane) <> Nothing then
  46.         if verbose then
  47.           line := line + ' space lane'
  48.         else
  49.           line := line + ' SL';
  50.       if (etc and StarDock) <> Nothing then
  51.         if verbose then
  52.           line := line + ' Star Dock'
  53.         else
  54.           line := line + ' SD';
  55.       if (etc and Avoid) <> Nothing then
  56.         if verbose then
  57.           line := line + ' avoid'
  58.         else
  59.           line := line + ' AV';
  60.       if (etc and HasFighters) <> Nothing then
  61.         if verbose then
  62.           line := line + ' has fighters'
  63.         else
  64.           line := line + ' F';
  65.       if (etc and NoteExists) <> Nothing then
  66.         line := line + DisplayNote( s );
  67.       if number = 1 then
  68.         if AppearanceCount(s) = 1 then
  69.           if verbose then
  70.             line := line + ' dead end (' + str(HowFar( s ),1) + ')'
  71.           else
  72.             line := line + ' DE(' + str(HowFar(s),1) + ')';
  73.       writeln( line);
  74.       if ToFile then
  75.         writeln( TheFile, line );
  76.     end; {with}
  77. end; {DisplaySector}
  78.  
  79. type
  80.   WhichStuff = (any, PortOnly, NoteOnly, UnExpOnly, FighterOnly, SpecPort );
  81.  
  82. procedure EliminateUnwanted( var distances   : distanceArray;
  83.                                  keepMe      : WhichStuff;
  84.                              var HowManyLeft : sectorIndex;
  85.                                  PortClass   : stuff );
  86. { Remove the sectors you don't want in the list by pushing them to the back}
  87. var
  88.   whichSector : sector;
  89.   keep : boolean;
  90. begin
  91.   HowManyLeft := 0;
  92.   for whichSector := 1 to MaxSector do
  93.     begin
  94.       case keepMe of
  95.         any : keep := distances[ whichSector ].d <> maxint;
  96.         PortOnly : keep := space.sectors[whichSector].porttype <> NotAPort;
  97.         NoteOnly : keep := space.sectors[whichSector].etc and NoteExists
  98.                            <> Nothing;
  99.         UnExpOnly: keep := (space.sectors[whichSector].number = UnExplored)
  100.                            and (distances[ whichSector ].d <> maxint);
  101.         FighterOnly : keep := (space.sectors[whichSector].etc and HasFighters)
  102.                            <> Nothing;
  103.         SpecPort : keep := space.sectors[whichSector].porttype = PortClass;
  104.       end; {case}
  105.       if keep then
  106.         begin
  107.           HowManyLeft := HowManyLeft + 1;
  108.           distances[ howManyLeft ] := distances[ whichSector ];
  109.         end; {if}
  110.     end; {for}
  111.   write('Total of ', HowManyLeft );
  112.   case keepMe of
  113.     any      : writeln(' sectors from base sector');
  114.     PortOnly : writeln(' known ports');
  115.     NoteOnly : writeln(' sectors with notes');
  116.     UnExpOnly: writeln(' unexplored sectors with known position');
  117.     FighterOnly : writeln(' fighter clouds');
  118.     SpecPort : writeln(' ports of type ', status( PortClass ) );
  119.   end; {case}
  120. end; {EliminateUnwanted}
  121.  
  122. procedure FindSmallest( var distances : DistanceArray;
  123.                         lowest, highest : sector );
  124. { Examine the distance array from lowest to highest, and move the
  125. sector at smallest distance into the "lowest" slot. }
  126. var
  127.   temp     : dist;
  128.   s,
  129.   smallest : sector;
  130. begin
  131.   Smallest := lowest;
  132.   for s := lowest to highest do
  133.     if distances[ s ].d < distances[ smallest ].d then
  134.       smallest := s;
  135.   temp := distances[ smallest ];
  136.   distances[ smallest ] := distances[ lowest ];
  137.   distances[ lowest ] := temp;
  138. end; {FindSmallest}
  139.  
  140. procedure nearestStuff( Filter : WhichStuff; StuffType : stuff );
  141. var
  142.   Number : sectorIndex;
  143.   s, n : integer;
  144.   log  : boolean;
  145.   f    : text;
  146. begin
  147.   if SetUpDistances then
  148.     begin
  149.       EliminateUnwanted( distances, filter, Number, StuffType );
  150.       log := prompt( 'Log to disk? ');
  151.       if log then
  152.         begin
  153.           assign( f, GetNewFileName('File name for report?  ', 'report.txt') );
  154.           rewrite( f );
  155.         end;
  156.       if Number <> 0 then
  157.         begin
  158.           for n := 1 to Number do
  159.             begin
  160.               FindSmallest( distances, n, Number );
  161.               DisplaySector( distances[ n ].s, ' Dist:', distances[n].d, log, f );
  162.               if n mod 20 = 0 then
  163.                 if not prompt( 'more? ') then
  164.                   begin
  165.                     if log then
  166.                       close( f );
  167.                       exit;
  168.                   end;
  169.             end; {for}
  170.         end; {if}
  171.       if log then
  172.         close( f );
  173.     end; {if}
  174. end; {nearport}
  175.  
  176. procedure SortPorts( var NumPorts : sectorindex );
  177. var
  178.   s, n : integer;
  179. begin
  180.   NumPorts := 0;
  181.   if SetUpDistances then
  182.     begin
  183.       EliminateUnwanted( distances, PortOnly, NumPorts, 0 );
  184.       writeln('Sorting...');
  185.       SortDistances( distances, NumPorts )
  186.     end; {if}
  187. end; {SortPorts}